package com.xique.park.controller.web;

import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.request.web.parkInfo.ParkBaseInfoSaveRequest;
import com.xique.park.bean.request.web.parkInfo.ParkParamConfigSaveRequest;
import com.xique.park.bean.request.web.parkInfo.ParkPayConfigSaveRequest;
import com.xique.park.service.biz.service.IParkDetailInfoBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 车场参数controller
 *
 * @author xique
 * @date 2021-12-13
 */
@RestController
@RequestMapping("/web/park")
public class WebParkDetailInfoController extends BaseController {

    @Autowired
    private IParkDetailInfoBizService parkDetailInfoBizService;

    /**
     * 获取车场基本信息
     */
    @PreAuthorize(hasPermi = "park:info:query")
    @GetMapping(value = "/getBaseInfo")
    public AjaxResult getParkBaseInfo() {
        return parkDetailInfoBizService.getParkBaseInfo();
    }

    /**
     * 保存车场基本信息
     */
    @PreAuthorize(hasPermi = "park:info:edit")
    @Log(title = "车场基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/saveBaseInfo")
    public AjaxResult saveBaseInfo(@Validated @RequestBody ParkBaseInfoSaveRequest request) {
        return parkDetailInfoBizService.saveBaseInfo(request);
    }

    /**
     * 获取车场全局参数
     */
    @PreAuthorize(hasPermi = "park:info:query")
    @GetMapping(value = "/getParamConfig")
    public AjaxResult getParamConfig() {
        return parkDetailInfoBizService.getParamConfig();
    }

    @PreAuthorize(hasPermi = "park:info:edit")
    @Log(title = "车场全局参数", businessType = BusinessType.UPDATE)
    @PostMapping("/saveParamConfig")
    public AjaxResult saveParkConfigInfo(@Validated @RequestBody ParkParamConfigSaveRequest request) {
        return parkDetailInfoBizService.saveParkConfigInfo(request);
    }

    /**
     * 获取车场支付配置
     * 目前先和旧版本保持一致，获取PP的
     */
    @PreAuthorize(hasPermi = "park:info:query")
    @GetMapping(value = "/getPayConfig")
    public AjaxResult getPayConfig(@RequestParam(value = "parkId",required = false) Long parkId) {
        return parkDetailInfoBizService.getPayConfig(parkId);
    }

    @PreAuthorize(hasPermi = "park:info:edit")
    @Log(title = "车场支付配置", businessType = BusinessType.UPDATE)
    @PostMapping("/savePayConfig")
    public AjaxResult savePayConfig(@Validated @RequestBody ParkPayConfigSaveRequest request) {
        return parkDetailInfoBizService.savePayConfig(request);
    }

    /**
     * 获取场内预付码url
     */
    @PreAuthorize(hasPermi = "park:info:query")
    @GetMapping(value = "/getPrePayUrl")
    public AjaxResult getPrePayUrl() {
        return parkDetailInfoBizService.getPrePayUrl();
    }


    /**
     * 获取场内预付码url
     */
    @PreAuthorize(hasPermi = "park:info:query")
    @GetMapping(value = "/v1/getPrePayUrl")
    public AjaxResult getPrePayUrlV1() {
        return parkDetailInfoBizService.getPrePayUrlV1();
    }

}
